#ifndef VOLUMEACTIVATION_H
#define VOLUMEACTIVATION_H

#include<QObject>
#include<QJsonDocument>
#include<QJsonObject>
#include<QtNetwork/QHostAddress>
#include<QtNetwork/QHostInfo>
#include<QSettings>
#include<QFileInfo>
#include<QDir>
#include<QTextCodec>
#include<QNetworkInterface>
#include<QJsonArray>
#include<QApplication>
#include<QTimer>
#include<QThread>
#include <mosquitto.h>
#include <QDBusConnection>
#include "receive_dbus.h"
#include "definition.h"

#define PORT  1883

using namespace std;

extern "C" {
extern int encrypt_hardware_info(const char* hw_info, unsigned int in_size, unsigned char* out, unsigned int *out_size);
}

class VolumeActivation : public QObject
{
    Q_OBJECT

public:
    VolumeActivation(QObject *parent = nullptr);
    ~VolumeActivation();

    //发布消息
    static void mqttPublish(struct mosquitto *mosq, char *topic);
    //订阅主题
    void mqttSubscription(char *topic);
    //接收消息
//    void mqttGetMessage();
    //连接回调
    static void myConnectCallback(struct mosquitto *mosq, void *userdata, int result);
    //发布回调
    static void myPublishCallback(struct mosquitto *mosq, void *obj, int mid);
//    void callback(struct mosquitto *mosq, void *obj, int mid)
    //消息回调
    static void myMessageCallback(struct mosquitto *mosq, void *userdata, const struct mosquitto_message *message);
    //查找server端ip
    void searchServerIp();


    struct mosquitto *mosq = nullptr;
    static int activate_ret;//0激活成功 1激活失败（activate  ret值）
    static int recycle_ret;//0回收成功 1回收失败（recycle  ret值）
    static QString act_code;//激活码
    static QString ser_num_by_server; //服务端回传的服务序列号
    static QString _sn;//根据服务端回传的服务序列号计算注册码
    QString server_dns = nullptr; //服务端IP
    int connect_num;//连接次数

    static QString topic_activate;
    static QString topic_recycle;
    static QString topic_status_response;

    QTimer *timer;

    static QMap<QString,QString> map;

private:
    static bool is_subscribe_register;

public slots:
    //建立MQTT连接
    void mqttConnect();
    void sendActivationStateSlot();

};

#endif // VOLUMEACTIVATION_H
